package time_20230810;

/**
 * @author lizhen
 * @date 2023/8/10 15:47
 */

import java.util.Arrays;

/**
 * 344.反转字符串
 */
public class ReverseString {
    public static void main(String[] args) {
        char[] s = {'a', '2', 'x', 'c', 'q'};
        reverseString2(s);
    }

    public static void reverseString(char[] s) {
        String a = String.valueOf(s);
        StringBuilder sb = new StringBuilder(a);
        StringBuilder reverse = sb.reverse();
        System.out.println(reverse);
    }

    public static void reverseString2(char[] s) {
        int l = 0;
        int r = s.length - 1;
        while (l < r) {
            char temp = s[l];
            s[l] = s[r];
            s[r] = temp;
            l++;
            r--;
        }

        System.out.println(Arrays.toString(s));
    }
}
